import { Reducer } from "redux";
import { SET_USER } from "store/constants";
import { IAction } from "../type";

export interface ITemplate {
    id: number;
    name: string;
    cover: string;
    author: string;
    used: number;
    hot?: boolean;
    new?: boolean;
    [key: string]: any;
}

export interface IState {
    user: string;
    templateList: ITemplate[];
}

const defaultHomeState: IState = {
    user: "",
    templateList: [
        {
            id: 1,
            name: "简约轻奢大理石婚礼请柬模板H5",
            cover: "https://img1.maka.im/template/T_CMD3Q3ZV_v1.jpg?x-oss-process=image/resize,w_360/format,webp",
            author: "MrChensir",
            used: 500,
            hot: true,
            new: true
        },
        {
            id: 2,
            name: "简约唯美毕业季纪念相册H5",
            cover: "https://img1.maka.im/template/T_ZNO2SAQ3_v2.jpg?x-oss-process=image/resize,w_360/format,webp",
            author: "MrChensir",
            used: 450,
            hot: true,
            new: true
        },
        {
            id: 3,
            name: "灰蓝色冰蓝石材肌理极简婚礼请柬邀请函",
            cover: "https://img1.maka.im/template/T_3Z1I0INX_v1.jpg?x-oss-process=image/resize,w_360/format,webp",
            author: "MrChensir",
            used: 800,
            hot: true
        },
        {
            id: 4,
            name: "白绿优雅纸品肌理底纹清新手绘水彩线条花叶婚礼请柬邀请函",
            cover: "https://img1.maka.im/template/T_LK7S01JR_v1.jpg?x-oss-process=image/resize,w_360/format,webp",
            author: "MrChensir",
            used: 220
        }
    ]
}

const homeReducer: Reducer<IState, IAction> = (state = defaultHomeState, action) => {
    switch(action.type){
        case SET_USER:
            return {
                ...state,
                user: action.payload
            }
        default:
            return state;
    }
}

export default homeReducer;